package com.heima.search.listen;

import com.heima.common.constants.ArticleConstants;
import com.heima.common.constants.WemediaConstants;
import com.heima.search.service.ArticleSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
public class KafkaListen {
    @Autowired
    private ArticleSearchService articleSearchService;

    @KafkaListener(topics = ArticleConstants.ARTICLE_PUBLISH_TOPIC)
    public void articlePublish(String message){
        articleSearchService.add(message);
    }

    @KafkaListener(topics = WemediaConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void articleUpOrDown(String message) throws IOException {
        articleSearchService.upOrDown(message);
    }
}
